﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pong
{
    class Pallete
    {
        //ATRIBUTOS (VARIÁVEIS, SUBSTANTIVOS...)

        Texture2D texture;
        public Vector2 position;
        public Rectangle size;//AQUI
        Vector2 velocity;//AQUI

        public int points;


        //MÉTODOS (FUNÇÕES, VERBOS...)

        public Pallete(Texture2D texture, Vector2 position)//<CONSTRUTOR!!!
        {
            this.texture = texture;//AQUI
            this.position = position;//AQUI
            this.velocity = new Vector2(0, 5);//AQUI
            this.size = texture.Bounds;//AQUI
            points = 0;
        }

        public void Update(GameWindow janela, List<Keys> teclas)//AQUI!!!
        {

            ManternaTela(janela);
                        
            #region Testando as Teclas

            foreach (Keys tecla in teclas)
            {
                if (Keyboard.GetState().IsKeyDown(tecla) 
                    && tecla == Keys.Down)
                {
                    position+=velocity;//AQUI
                }

                if (Keyboard.GetState().IsKeyDown(tecla)
                    && tecla == Keys.Up)
                {
                    position -= velocity;
                }

                if (Keyboard.GetState().IsKeyDown(tecla)
                    && tecla == Keys.Z)
                {
                    position += velocity;
                }

                if (Keyboard.GetState().IsKeyDown(tecla)
                    && tecla == Keys.A)
                {
                    position -= velocity;
                }
            }
            # endregion

            this.size.X = (int)position.X;
            this.size.Y = (int)position.Y;
        }

        public void ManternaTela(GameWindow janela)
        {
            if (position.Y <= 0)
            {
                position.Y = 0;
            }

            if (position.Y >= janela.ClientBounds.Height - size.Height)
            {
                position.Y = janela.ClientBounds.Height - size.Height;
            }

            if (position.X <= 0)
            {
                position.X = 0;
            }

            if (position.X >= janela.ClientBounds.Width - size.Width)
            {
                position.X = janela.ClientBounds.Width - size.Width;
            }

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }
    }
}
